package com.example.testspringes.threadtest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Description: //TODO
 * @ProjectName: testspringes
 * @Package: com.example.testspringes.threadtest
 * @Author: FX
 * @CreateDate: 2019/4/1 14:33
 * @Version: 1.0
 * Copyright: Copyright (c) 2019
 */
@Component
public class Server {
    @Autowired
    TestAsyn testAsyn;
    public  void start(){
        testAsyn.tt();
        ExecutorService executorService = Executors.newFixedThreadPool(3);
        long start = System.currentTimeMillis();
        for(int i=0;i<3;i++){
            executorService.execute(new Task());
        }
        executorService.shutdown();
        while(true){
            if(executorService.isTerminated()){
                //System.out.println("Finally do something ");
                long end = System.currentTimeMillis();
                System.out.println("用时: " + (end - start) + "ms");
                break;
            }
        }
    }
}
